/// <license>
/// Copyright (c) 2002-2008, DotNetNuke Corporation
/// All rights reserved
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
/// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
/// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
/// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
/// of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
/// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
/// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
/// DEALINGS IN THE SOFTWARE.
/// </license>

#region Using Statements

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.ComponentModel; 

#endregion

namespace DotNetNuke.ModuleToolkit.Controls
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// Special localized version of a <see cref="Label"/> that uses the <see cref="Localization"/> service to localize the text
    /// in the <see cref="Label"/>.
    /// </summary>
    /// <history>
    /// 	[anurse]	08/11/2006	created
    /// </history>
    /// -----------------------------------------------------------------------------
    public class LocalizedLabel : Label
    {

        #region Private Fields

        private string resourceKey;
        private bool useGlobalResources = false; 

        #endregion

        #region Public Properties

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// A String that contains the localization resource key for the Label text
        /// </summary>
        /// <remarks>Defaults to '[id].Text', where [id] is the value of the <see cref="System.Web.UI.Control.ID"/> property</remarks>
        /// <history>
        /// 	[anurse]	05/16/2006	created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(true),
        Category("Localization"),
        DefaultValue(""),
        Description("The Resource Key to use to localize the Label Text")]
        public string ResourceKey
        {
            get
            {
                if (String.IsNullOrEmpty(resourceKey))
                    return String.Format("{0}.Text", this.ID);
                return resourceKey;
            }
            set { resourceKey = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// A String that defines the Label text
        /// </summary>
        /// <history>
        /// 	[anurse]	05/16/2006	created
        /// </history>
        /// -----------------------------------------------------------------------------
        public override string Text
        {
            get
            {
                if (DesignMode)
                    return base.Text;
                else
                    return Localization.Localization.LocalizeString(this, ResourceKey, base.Text, UseGlobalResources);
            }
            set
            {
                base.Text = value;
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// A Boolean that determines if global resources should be used to localize the
        /// Label text
        /// </summary>
        /// <history>
        /// 	[anurse]	05/16/2006	created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(true),
        Category("Localization"),
        DefaultValue(""),
        Description("Indicates if global or local resources should be used to localize the text")]
        public bool UseGlobalResources
        {
            get { return useGlobalResources; }
            set { useGlobalResources = value; }
        } 

        #endregion

    }
}
